using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace rocketjump
{
    public class Particle
    {
        public Texture2D Texture { get; set; }        // The texture that will be drawn to represent the particle
        public Vector2 Position { get; set; }        // The current position of the particle        
        public Vector2 Velocity { get; set; }        // The speed of the particle at the current instance
        public float Angle { get; set; }            // The current angle of rotation of the particle
        public float AngularVelocity { get; set; }    // The speed that the angle is changing
        public Color m_color { get; set; }            // The color of the particle
        public int m_type { get; private set; }            // The color of the particle
        public float Size { get; set; }                // The size of the particle
        public int TTL { get; set; }                // The 'time to live' of the particle
        private Random random;

        public Particle(Texture2D texture, Vector2 position, Vector2 velocity,
            float angle, float angularVelocity, int type, float size, int ttl)
        {
            Texture = texture;
            Position = new Vector2(position.X + JumpGame.primary_camera.Position.X, position.Y + JumpGame.primary_camera.Position.Y);
            Velocity = new Vector2(velocity.X, velocity.Y);
            Angle = angle;
            AngularVelocity = angularVelocity;
            m_type = type;
            switch (type)
            {
                case 1:
                    m_color = Color.Red;
                    break;
            }
            Size = size;
            TTL = ttl;

            random = new Random();
        }

        public void Update()
        {
            TTL--;
            Position += Velocity +new Vector2((int)(10 * random.NextDouble()), (int)(10 * random.NextDouble()));
            Angle += AngularVelocity;
            switch (m_type)
            {
                case 1:
                    //Position += Velocity +new Vector2((int)(10 * random.NextDouble()), (int)(10 * random.NextDouble()));
                    Angle += AngularVelocity;
                    break;
                case 2:
                    Position += new Vector2(random.Next(-3, 4), random.Next(3, 5));
                    break;
                default:
                    Position += Velocity +new Vector2((int)(10 * random.NextDouble()), (int)(10 * random.NextDouble()));
                    break;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
            Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);


            Color tempColor;
            switch (m_type) 
            {
                case 1:
                    float dist = Angle * 10 + TTL * 20;
                    tempColor = new Color(m_color.R, (int)(random.Next(230, 250) - dist), random.Next(0, 20));
                    break;
                case 2:
                    int blue = random.Next(200, 240);
                    tempColor = new Color(blue, blue, 255);
                    break;
                default:
                    tempColor = Color.Black;
                    break;
            }
            spriteBatch.Draw(Texture, Position-JumpGame.primary_camera.Position, sourceRectangle, tempColor,
                Angle, origin, Size, SpriteEffects.None, 0f);
        }

    }
}
